package com.techfied.hex;

import java.awt.Color;
import java.awt.event.MouseAdapter;
import java.util.ArrayList;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.table.AbstractTableModel;

import org.w3c.dom.events.MouseEvent;

public class TableModel extends AbstractTableModel {

	FIFO<Cell> data = new FIFO<Cell>(HexPane.Nc * HexPane.Nr);
	List<String> columnNames = new ArrayList<String>();

	public TableModel() {
		for (int i = 1; i <= HexPane.Nc; i++) {
			columnNames.add(i + "");
		}
	}

	@Override
	public int getColumnCount() {
		return HexPane.Nc;
	}

	@Override
	public int getRowCount() {
		return HexPane.Nr;
	}

	@Override
	public String getColumnName(int col) {
		return columnNames.get(col);
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		int index = rowIndex * HexPane.Nc + columnIndex;
		if (data.size() > index) {
			return data.get(index);
		}
		return null;
	}

	public void append(byte[] bytes) {
		for (int i = 0; i < bytes.length; i++) {
			Cell cell = new Cell(bytes[i]);
			data.add(cell);
		}
	}

	public void prepend(byte[] bytes) {
		for (int i = bytes.length - 1; i >= 0; i--) {
			Cell cell = new Cell(bytes[i]);
			data.addFirst(cell);

		}
	}

	public String toString() {
		String str = "";
		for (Cell cell : data) {
			str += cell + ", ";
		}
		return str;
	}

	public int getSize() {
		return data.size();
	}

	@Override
	public boolean isCellEditable(int row, int col) {
		
		return false;
	}
}
